package com.example.activelifecycletest.broadcast;

import android.content.ComponentName;
import android.content.Intent;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.example.activelifecycletest.R;

/**
 * 广播活动类
 * @author zhangding
 * @date 2022年04月21日15:24:52
 */
public class MyBroadcastActivity extends AppCompatActivity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        Log.d("zhang","进入到活动");
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button button = (Button) findViewById(R.id.button);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                    Log.d("zhang","进入监听器");
                    Intent intent = new Intent("MY_BROADCAST");
                    intent.setComponent(new ComponentName(getPackageName(), "com.example.activelifecycletest.broadcast.MyBroadcastReceiver"));
                    sendBroadcast(intent);
            }
        });
    }
}
